package com.mail.controller;

import com.mail.pojo.Mail;
import com.mail.service.MailService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class MailController {
	@Resource
	MailService mailService;
	@ResponseBody
	@PostMapping("/sendSimpleMail")
	String sendSimpleMail(Mail mail) {
		mailService.sendSimpleMailManager(mail);
		return "简单邮件发送成功";
	}
	@ResponseBody
	@PostMapping("/sendMailWithFile")
	String sendMailWithFile(Mail mail, MultipartFile uploadFile, HttpServletRequest request) throws IOException {
		String path="D:\\学习\\Java开发\\项目\\实训教科书代码\\chapter18\\Mail\\src\\main\\resources\\static\\uploadFile";
		String filename = uploadFile.getOriginalFilename();
		File file = new File(path, filename);
		uploadFile.transferTo(file);
		mail.setFile(file);
		mailService.sendMailWithFile(mail);
		return "带附件的邮件发送成功";
	}
	@ResponseBody
	@PostMapping("/sendTemplateMail")
	String sendTemplateMail(Mail mail,String username,String orderNo,String amount,String mobile) {
		mailService.sendTemplateMail(mail,username,orderNo,amount,mobile);
		return "模板邮件发送成功";
	}
}
